package com.yourenbang.lingyun.transaction.mapper;

import com.yourenbang.lingyun.transaction.web.domain.dto.PullDataDTO;
import com.yourenbang.lingyun.transaction.web.domain.dto.pay.FundPayQueryParam;
import com.yourenbang.lingyun.transaction.web.domain.po.FundAccountWithdrawPayment;
import com.yourenbang.lingyun.transaction.web.domain.vo.fund.T1WithdrawBillVO;
import com.yourenbang.transaction.api.model.dto.manage.ExportWithdrawListDTO;
import com.yourenbang.transaction.api.model.dto.manage.QueryWithdrawListDTO;
import com.yourenbang.transaction.api.model.dto.manage.QueryWithdrawTerDTO;
import com.yourenbang.transaction.api.model.vo.manage.ExportDayTerminalVO;
import com.yourenbang.transaction.api.model.vo.manage.QueryWithdrawDetailVO;
import com.yourenbang.transaction.api.model.vo.manage.QueryWithdrawListVO;
import com.yourenbang.transaction.api.model.vo.manage.QueryWithdrawTerVO;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

public interface TransactionFundAccountWithdrawPaymentMapper {

    /**
     * 插入
     */
    int insert(FundAccountWithdrawPayment payment);

    /**
     * 更新
     */
    int updateById(FundAccountWithdrawPayment payment);

    /**
     * 更新(根据订单号)
     */
    int updateByOrderSn(FundAccountWithdrawPayment payment);

    /**
     * 根据id获取提现记录
     */
    FundAccountWithdrawPayment selectByPrimaryKey(@Param("platNo") Short platNo, Integer fundAccountWithdrawPaymentId);

    /**
     * 根据第三方订单号获取提现记录
     */
    FundAccountWithdrawPayment findByThirdOrderId(@Param("platNo") Short platNo, @Param("thirdOrderId") String thirdOrderId);

    /**
     * 根据订单号获取提现记录
     */
    FundAccountWithdrawPayment findByOrderSn(@Param("platNo") Short platNo, @Param("orderSn") String orderSn);

    /**
     * 需处理的提现查询任务
     */
    List<FundAccountWithdrawPayment> findFundIng(@Param("platNo") Short platNo, @Param("param") FundPayQueryParam param);

    /**
     * 需处理的提现查询任务(自定义查询范围)
     */
    List<FundAccountWithdrawPayment> findFundIngSetTime(@Param("platNo") Short platNo, @Param("param") FundPayQueryParam param);

    /**
     * 查询提现机具
     */
    List<QueryWithdrawTerVO> queryWithdrawAndTerminal(@Param("dto") QueryWithdrawTerDTO dto);

    List<Map<String, Object>> listPledgeRefundBill(@Param("dto") PullDataDTO dto);

    /**
     * 查询提现列表
     *
     * @param dto
     * @return
     */
    List<QueryWithdrawListVO> selectWithdrawList(@Param("dto") QueryWithdrawListDTO dto);

    /**
     * 导出提现列表
     *
     * @param dto
     * @return
     */
    List<QueryWithdrawListVO> selectExportWithdrawList(@Param("dto") ExportWithdrawListDTO dto);

    QueryWithdrawDetailVO selectWithdrawDetail(@Param("platNo") Short platNo, @Param("fundAccountWithdrawPaymentId") Integer fundAccountWithdrawPaymentId);

    List<ExportDayTerminalVO> queryWithdrawTerWs(@Param("platNo") Short platNo, @Param("dayNum") Integer dayNum);

    List<ExportDayTerminalVO> queryWithdrawTerXlf(@Param("platNo") Short platNo, @Param("dayNum") Integer dayNum);

    /**
     * 账户已提金额
     */
    BigDecimal accountWithdrawed(@Param("platNo") Short platNo, @Param("accountType") Integer accountType, @Param("userBaseId") String userBaseId);

    /**
     * 通过支付方式，和时间查询待处理提现订单
     * @param platNo 平台
     * @param payType 支付方式，对应pay_getway
     * @param createTime 提现订单创建时间
     * @return 符合条件的提现订单列表
     */
    List<FundAccountWithdrawPayment> findFundIngByPayTypeAndCreateTime(@Param("platNo") Short platNo,
                                                                       @Param("payType") String payType,
                                                                       @Param("createTime") String createTime);


    /**
     * 按时间查询账户已提金额
     */
    BigDecimal accountWithdrawByTime(@Param("platNo") Short platNo,
                                 @Param("accountType") Integer accountType,
                                 @Param("userBaseId") String userBaseId,
                                 @Param("beginCreateTime") String beginCreateTime,
                                 @Param("endCreateTime") String endCreateTime);
    /**
     * 查询次日提现统计
     */
    List<T1WithdrawBillVO> queryT1WithdrawAlipayBill(@Param("platNo") Short platNo,
                                                     @Param("withdrawStatus") Integer withdrawStatus,
                                                     @Param("batchNumber") String batchNumber);
    /**
     * 查询次日提现统计
     */
    List<T1WithdrawBillVO> queryT1WithdrawBankBill(@Param("platNo") Short platNo,
                                           @Param("withdrawStatus") Integer withdrawStatus,
                                           @Param("batchNumber") String batchNumber);

    /**
     * 查询待发起提现的记录
     * @param platNo
     * @param batchNumber
     * @return
     */
    List<FundAccountWithdrawPayment> queryT1WithdrawWaitPay(@Param("platNo") Short platNo,
                                                                       @Param("batchNumber") String batchNumber);
    /**
     * 查询待发起提现的记录的支付通道
     * @param platNo
     * @param batchNumber
     * @return
     */
    List<FundAccountWithdrawPayment> queryT1WithdrawWaitPayType(@Param("platNo") Short platNo,
                                                                       @Param("batchNumber") String batchNumber);

    /**
     * 获取体现的退款记录数
     * @param platNo 平台
     * @param orderSn 提现订单号
     * @return 记录数，大于0就是已经退款
     */
    Integer getWithdrawReturnRecordCount(@Param("platNo") Short platNo, @Param("orderSn") String orderSn);
}